package cn.tuling.example2;

/**
 * 美颜相机
 */
public class DecoratorTest {
    public static void main(String[] args) {
        Component component = new Camera();
        component.operator();

        System.out.println("---------");

        Component concreteDecorator1 = new ConcreteDecorator1(component);
        concreteDecorator1.operator();

        System.out.println("---------");

        Component concreteComponent2 = new ConcreteDecorator2(concreteDecorator1);
        concreteComponent2.operator();
    }
}

interface Component {
    void operator();
}

class Camera implements Component {

    @Override
    public void operator() {
        System.out.println("拍照");
    }
}

abstract class Decorator implements Component {
    Component component;

    public Decorator(Component component) {
        this.component = component;
    }
}

class ConcreteDecorator1 extends Decorator {

    public ConcreteDecorator1(Component component) {
        super(component);
    }

    @Override
    public void operator() {
        System.out.println("添加美颜");
        component.operator();
    }
}

class ConcreteDecorator2 extends Decorator {

    public ConcreteDecorator2(Component component) {
        super(component);
    }

    @Override
    public void operator() {
        System.out.println("添加滤镜");
        component.operator();
    }
}
